package br.com.dev.tcc.model;

import java.util.List;

import android.content.Context;
import br.com.dev.tcc.bean.sinistro.Sinistro;
import br.com.dev.tcc.database.DatabaseHelper;
import br.com.dev.tcc.database.dao.SinistroDAO;

public class SinistroModel {

	private DatabaseHelper dbhelper;
	private List<Sinistro> lista;
	private Context context;

	public SinistroModel(Context context) {

		this.context = context;
		this.dbhelper = new DatabaseHelper(context);
	}

	public List<Sinistro> lista() {

		SinistroDAO dao = new SinistroDAO(dbhelper);
		lista = dao.lista();
		return lista;
	}
	
	public boolean atualiza(Sinistro sinistro){
		
		SinistroDAO dao = new SinistroDAO(dbhelper);
		return dao.atualizaStatus(sinistro);
	}
	
	public boolean salva(Sinistro sinistro){
		
		SinistroDAO dao = new SinistroDAO(dbhelper);
		boolean salvou = false;
		try{
			salvou = dao.salva(context, sinistro);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return salvou;
	}
	
	public boolean remove(int idSinistro){
		
		SinistroDAO dao = new SinistroDAO(dbhelper);
		return dao.remove(idSinistro);
	}
}
